package nio;

import java.io.File;
import java.io.FileOutputStream;
import java.nio.charset.Charset;
import java.nio.file.FileStore;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;

/**
 * Created by Administrator on 2017/10/22 022.
 */
public class FilesDemo
{
    public static void main(String[] args) throws Exception
    {
        Path path = Paths.get(".");
        System.out.println(path.getNameCount());
        System.out.println(path.getRoot());

//        Files.copy(Paths.get("D:\\itellijIdea_wk\\JavaDemo\\src\\nio\\CharsetDemo.java"), new FileOutputStream(new File("copy.txt")));
        List<String> lines = Files.readAllLines(Paths.get("D:\\itellijIdea_wk\\JavaDemo\\src\\nio\\CharsetDemo.java"));
        lines.forEach(System.out::println);
        System.out.println(Files.size(Paths.get("D:\\itellijIdea_wk\\JavaDemo\\src\\nio\\CharsetDemo.java")));
        Files.write(Paths.get("D:\\itellijIdea_wk\\JavaDemo\\src\\nio\\test.txt"), lines, Charset.forName("utf-8"));
        Files.lines(Paths.get("D:\\itellijIdea_wk\\JavaDemo\\src\\nio\\CharsetDemo.java"))
                .forEach(System.out::println);
        FileStore fs = Files.getFileStore(Paths.get("C:"));
        System.out.println("C盘总容量：" + fs.getTotalSpace()/Math.pow(2, 30) + "GB");
        System.out.println("C盘剩余：" + fs.getUsableSpace()/Math.pow(2, 30) + "GB");
    }
}
